<template>
  <el-dialog v-dialogDrag :visible.sync="dialog" width="880px" :close-on-click-modal="false" :before-close="reset">
    <span slot="title" class="dialog-title">工程维护</span>
    <div class="dialoginfo">
      <el-form ref="reffromDate" :model="fromDate" label-width="130px">
        <el-form-item label="归档号：" prop="fileNo">
          <el-input v-model="fromDate.fileNo"></el-input>
        </el-form-item>
        <el-form-item label="安全协议：" prop="securityAgreement">
          <el-radio-group v-model="fromDate.securityAgreement">
            <el-radio :label="1">是</el-radio>
            <el-radio :label="2">否</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="报审标识：" prop="reportMark">
          <el-radio-group v-model="fromDate.reportMark">
            <el-radio :label="1">是</el-radio>
            <el-radio :label="2">否</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="委托书有效性：" prop="entrustEffectiveness">
          <el-radio-group v-model="fromDate.entrustEffectiveness">
            <el-radio :label="1">是</el-radio>
            <el-radio :label="2">否</el-radio>
          </el-radio-group>
          <el-input v-model="fromDate.entrustEffectivenessRemark" placeholder="否则需备注异常原因" style="margin-left:40px"></el-input>
        </el-form-item>
        <el-form-item label="停工/缓建标识：" prop="shutdownMark">
          <el-radio-group v-model="fromDate.shutdownMark">
            <el-radio :label="1">是</el-radio>
            <el-radio :label="2">否</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="债权人异常标识：" prop="creditorAbnormalMark">
          <el-radio-group v-model="fromDate.creditorAbnormalMark">
            <el-radio :label="1">是</el-radio>
            <el-radio :label="2">否</el-radio>
          </el-radio-group>
          <el-input v-model="fromDate.creditorAbnormalRemark" placeholder="是则需备注异常原因" style="margin-left:40px"></el-input>
        </el-form-item>
        <el-form-item label="需完善事项：" prop="needItem">
          <el-input v-model="fromDate.needItem" placeholder="请填写备注" class="textarea" type="textarea" resize="none" rows="1"></el-input>
        </el-form-item>
        <div style="display:flex">
          <el-form-item label="结算量：" prop="statementNum">
            <el-input v-model="fromDate.statementNum" placeholder="请输入" type="Number" clearable>
              <template slot="append">吨</template>
            </el-input>
          </el-form-item>
          <el-form-item label="结算金额：" prop="statementAmount">
            <el-input v-model="fromDate.statementAmount" placeholder="请输入" type="Number" clearable>
            </el-input>
          </el-form-item>
        </div>
        <el-form-item label="结算完结时间：" prop="statementEndTime">
          <el-date-picker v-model="fromDate.statementEndTime" type="datetime" value-format="yyyy-MM-dd HH:mm:ss" placeholder="选择日期时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button class="bottom_all_two" @click="reset">取 消</el-button>
      <el-button class="bottom_all" style="margin-left: 24px" @click="submit">确 定</el-button>
    </span>
  </el-dialog>
</template>
<script>
import { queryMaintenance, saveMaintenance } from "@/api/internetSales/engineeringControl.js";
export default {
  props: {
    dialog: {
      type: Boolean,
      default: false
    },
    low: {
      type: Object,
      default: new Object()
    }
  },
  data() {
    return {
      fromDate: {
        id: '',
        engineeringId: '',
        fileNo: '',
        securityAgreement: '',
        reportMark: '',
        entrustEffectiveness: '',
        entrustEffectivenessRemark: '',
        shutdownMark: 2,
        creditorAbnormalMark: 2,
        creditorAbnormalRemark: '',
        needItem: '',
        statementNum: '',
        statementAmount: '',
        statementEndTime: ''
      }
    }
  },
  watch: {
    dialog() {
      if (this.dialog) {
        queryMaintenance({ engineeringId: this.low.id }).then(res => {
          this.fromDate.engineeringId = this.low.id
          if (res.data) {
            for (let key in this.fromDate) {
              this.fromDate[key] = res.data[key]
            }
            return
          }
          this.fromDate = {
            id: '',
            engineeringId: '',
            fileNo: '',
            securityAgreement: '',
            reportMark: '',
            entrustEffectiveness: '',
            entrustEffectivenessRemark: '',
            shutdownMark: 2,
            creditorAbnormalMark: 2,
            creditorAbnormalRemark: '',
            needItem: '',
            statementNum: '',
            statementAmount: '',
            statementEndTime: ''
          }
        })
      }
    },
  },
  methods: {
    reset() {
      this.$emit('reset', 'dialog2')
    },
    submit() {
      this.$refs.reffromDate.validate((valid) => {
        if (valid) {
          this.fromDate.engineeringId = this.low.id
          saveMaintenance(this.fromDate).then(res => {
            if (res.code == 1001) {
              this.$message({
                message: '保存成功',
                type: "success",
              });
            }
            this.$emit('submit', 'dialog2')
          })
        } else {
          return false;
        }
      });

    },
  }
}
</script>
<style lang="scss" scoped>
.el-input,
.el-select {
  width: 240px;
}
</style>


